#ifndef ALGO_BUFFER_H
#define ALGO_BUFFER_H

#include "algo_type.h"

// TYPEDEF
typedef struct
{
    int32 *i32p_data;
    uint32 u32_length;
    uint32 u32_pointer;
    uint32 u32_count;
} cycle_buffer;

typedef struct
{
    int32 *i32p_coefficient;
    uint32 u32_length;
    int32 i32_magnification;
} filter_window;

typedef struct
{
    int32 i32_min;
    int32 i32_max;
    uint32 u32_count;
    uint32 u32_size;
    int32 i32_sum;
} boxcar;

// Public functions declaration
void Buffer_Init( cycle_buffer *tp_buffer, int32 *i32p_data, uint32 u32_length );
void Buffer_Reset( cycle_buffer *tp_buffer );
void Buffer_Push( cycle_buffer *tp_buffer, int32 i32_value );
void Buffer_Pop( cycle_buffer *tp_buffer );
int32 Buffer_Get( const cycle_buffer *tp_buffer, uint32 u32_index );
void Buffer_Replace( const cycle_buffer *tp_buffer, uint32 u32_index, int32 i32_value );
uint32 Buffer_Count( const cycle_buffer *tp_buffer, uint32 u32_num );
int32 Buffer_Diff( const cycle_buffer *tp_buffer, uint32 u32_index );
int32 Buffer_Mean( const cycle_buffer *tp_buffer, uint32 u32_num );
int32 Buffer_AbsMean( const cycle_buffer *tp_buffer, uint32 u32_num );
int32 Mean( const cycle_buffer *tp_buffer,
                   uint32 u32_first,
                   uint32 u32_last,
                   logical t_abs );
int32 Buffer_MeanOfMinN( const cycle_buffer *tp_buffer, int32 *i32p_temp, uint32 u32_first, uint32 u32_last);
int32 Buffer_MeanOfMaxN( const cycle_buffer *tp_buffer, int32 *i32p_temp, uint32 u32_first, uint32 u32_last );
int32 Var( const cycle_buffer *tp_buffer,
                   uint32 u32_first,
                   uint32 u32_last);
int32 Buffer_TrimedMean( const cycle_buffer *tp_buffer, uint32 u32_num );
int32 Buffer_TrimedVar( const cycle_buffer *tp_buffer, uint32 u32_num );
int32 Buffer_MeanAcc( const cycle_buffer *tp_buffer, uint32 u32_num );
int32 Buffer_Filter( const cycle_buffer *tp_buffer,
                     const filter_window *tp_window );
int32 Buffer_TrimedFilter( const cycle_buffer *tp_buffer,
                           const filter_window *tp_window,
                           int32 i32_upper,
                           int32 i32_lower );
void Boxcar_Init( boxcar *tp_boxcar, uint32 u32_size );
void Boxcar_Add( boxcar *tp_boxcar, int32 i32_value );
logical Boxcar_IsFull(boxcar *tp_boxcar);
int32 Boxcar_Output(boxcar *tp_boxcar);

#endif // ALGO_BUFFER_H
